
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author lqik2004
 */
public class stSearch {

    static void stSearch() {
        try {
            String insert;
            //asc 升序 desc 降序 select * from 表名 where 条件 order by 字段名 asc\desc
            insert = "SELECT DISTINCT * FROM STBase where day>= '" + bDay + "' and day<= '" + eDay + "' and month>= '" + bMonth + "' and month<='" + eMonth + "' and year>='" + bYear + "' and year<='" + eYear + "' ORDER BY date ASC";
            stDB.DBConnect();
            rs = stDB.DBSqlQuery(insert);
        } catch (SQLException ex) {
            Logger.getLogger(stSearch.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    static void stResult() throws SQLException {
        //防止出现“游标失效”问题；
        //boolean next = rs.next();
        //System.out.print(rs.getInt(1));
        int precursor = -1;
        int nowcursor;
        int computetime = 0;

        //解决出现“无效引用问题”,必须提前为getint赋值；, 
        try {
            while (rs.next()) {
                int compute = rs.getInt(9);
                int cursor = rs.getInt(10);

                nowcursor = cursor;
                //stFile2Data.Ind2pYear(rs.getInt(1));
                if (nowcursor == precursor || precursor == -1) {
                    computetime = computetime + compute;
                    precursor = nowcursor;


                } else {
                    precursor = nowcursor;
                    //输出信息（OUTPUT INFORMATION）
                    rs.previous();
                    String insert;
                    insert = "INSERT INTO STsum VALUES( '" + rs.getInt(1) + "','" + rs.getInt(2) + "','" + rs.getInt(3) + "','" + rs.getInt(4) + "','" + rs.getInt(5) + "','" + rs.getInt(6) + "','" + rs.getInt(7) + "','" + rs.getString(8) + "','" +
                            +computetime + "','" +
                            +rs.getInt(10) + "')";

                    stDB.DBConnect();
                    stDB.DBSqlAdd(insert);
                    rs.next();
                    //重新准备下一轮计算 PREPARE FOR NEXT TURN
                    computetime = compute;
                }
            }
            //对st最后的日期进行处理，把数据加入到数据库中。
            rs.previous();
            String insert;
            insert = "INSERT INTO STsum VALUES( '" + rs.getInt(1) + "','" + rs.getInt(2) + "','" + rs.getInt(3) + "','" + rs.getInt(4) + "','" + rs.getInt(5) + "','" + rs.getInt(6) + "','" + rs.getInt(7) + "','" + rs.getString(8) + "','" +
                    +computetime + "','" +
                    +rs.getInt(10) + "')";

            stDB.DBConnect();
            stDB.DBSqlAdd(insert);
            stDB.DBClosed();
        } catch (SQLException ex) {
            Logger.getLogger(stSearch.class.getName()).log(Level.SEVERE, null, ex);
        }
        String queryresult = "SELECT SUM,DATE FROM STSUM ";

        stDB.DBConnect();
        rsqueryresult = stDB.DBSqlQuery(queryresult);
        while (rsqueryresult.next()) {
            listSum.add(rsqueryresult.getInt(1));
            listDate.add(rsqueryresult.getInt(2));
            
        }
        stDB.DBClosed();
        //取得arrylist大小
        size = listDate.size();

    }

    static int getMaxList() {
        int x = listSum.get(0);
        for (int i = 0; i < listDate.size(); i++) {
            if (listSum.get(i) > x) {
                x = listSum.get(i);
            }
        }
        return x;
    }
    static ResultSet rs;
    static String bYear = stJudge.bYear;
    static String bMonth = stJudge.bMonth;
    static String bDay =stJudge.bDay;
    static String eYear = stJudge.eYear;
    static String eMonth = stJudge.eMonth;
    static String eDay = stJudge.eDay;
    static private ResultSet rsqueryresult;
    static private int date;
    static private int sum;
    static int size;
    static ArrayList<Integer> listDate = new ArrayList();
    static ArrayList<Integer> listSum = new ArrayList();
    }



        
        